local duorui = fk.CreateSkill {

  name = "joy__duorui",

  tags = {  },

}



duorui:addEffect(fk.EventPhaseStart, {
  name = "joy__duorui",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player == target and player:hasSkill(duorui.name) and player.phase == Player.Play then
      return table.find(player.room.alive_players, function(p) return p ~= player and not p:isKongcheng() end)
    end
  end,
  on_cost = function (self,event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    local to = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#joy__duorui-choose",duorui.name,true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local id = room:askForCardChosen(player, to, { card_data = { { "$Hand", to.player_cards[Player.Hand] } } }, duorui.name)
    local color = Fk:getCardById(id):getColorString()
    if color ~= "nocolor" then
      local mark = to:getTableMark( "@joy__duorui-turn")
      table.insertIfNeed(mark, color)
      room:setPlayerMark(to, "@joy__duorui-turn", mark)
    end
    room:moveCardTo(id,Card.PlayerHand,player,fk.ReasonPrey,duorui.name,nil,true,player)
  end,
})

duorui:addEffect(fk.CardUsing, {
  name = "#joy__duorui_trigger",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player == player.room.current
    and table.find(player.room.alive_players, function (p)
      return table.contains(p:getTableMark( "@joy__duorui-turn"), data.card:getColorString())
    end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = data.disresponsiveList or {}
    for _, p in ipairs(player.room.alive_players) do
      if table.contains(p:getTableMark( "@joy__duorui-turn"), data.card:getColorString()) then
        table.insertIfNeed(data.disresponsiveList, p.id)
      end
    end
  end,
})

return duorui